package com.ruoyi.web.controller.erp.transportation;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.erp.conventionaldata.domain.Transportation;
import com.ruoyi.erp.conventionaldata.service.TransportationService;
import com.ruoyi.erp.transport.service.TransportUnitTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author QiuRongYu@itcast.cn
 * @version 1.0
 * @date 2020/12/14
 */
@Api(tags = "运输方式")
@Controller
@RequestMapping("/transportation")
public class TransportationController extends BaseController {
    private String prefix = "erp/transportation";
    @Resource
    private TransportationService transportationService;
    @Resource
    TransportUnitTypeService transportUnitTypeService;

    @GetMapping()
    public String getList() {
        return prefix + "/list";
    }

    @GetMapping("/addList")
    public String addList()
    {
        return prefix + "/addList";
}
    @GetMapping("/edit")
    public String edit()
    {
        return prefix + "/edit";
    }
    @RequiresPermissions("transportation:transportation:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Transportation transportation)
    {
        List<Transportation> transportationList = transportationService.selectList(transportation);
        ExcelUtil<Transportation> util = new ExcelUtil<Transportation>(Transportation.class);
        return util.exportExcel(transportationList, "运输方式代码数据");
    }

    /**
     * 根据id删除
     */
    @RequiresPermissions("transportation:transportation:remove")
    @PostMapping("/remove")
    @ResponseBody
    public  AjaxResult remove(String ids){
        transportationService.remove(ids);
        return AjaxResult.success("删除成功");
    }
    /**
     * 修改运输方式代码
     */
    @RequiresPermissions("transportation:transportation:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edittransportation(Transportation transportation) {
            transportationService.edittransportation(transportation);
            return AjaxResult.success("修改成功");
    }
    /**
  * 根据id查询运输详情
  */
  @GetMapping("/edit/{id}")
  public String transportationselect(@PathVariable("id") String shipViaCode, ModelMap mmap) {
      Transportation transportation=transportationService.transportationselect(shipViaCode);
      mmap.put("transportation", transportation);
      return prefix + "/edit";
  }
    /**
     * 新增运输列表
     */
    @RequiresPermissions("transportation:transportation:add")
    @PostMapping("/addList")
    @ResponseBody
    public AjaxResult transportationAdd( Transportation transportation){
        transportationService.transportationAdd(transportation);
        return AjaxResult.success("添加成功");
    }
    /**
     * 查询所有的运输模式列表
     */
    @PostMapping("/transportationMode")
    @ResponseBody
    public TableDataInfo transportationMode() {
         return null;
    }
    @ApiOperation("运输单位类型查询条件")
    @RequestMapping(value = "selectTransportUnitTypeAll",method = {RequestMethod.POST})
    @ResponseBody
    public TableDataInfo selectTransportUnitTypeAll(){
        return getDataTable(transportUnitTypeService.selectTransportUnitTypeAll(null,null,null,null,null,null));
}
    /**
     * 查询运输列表
     */
    @ApiOperation(value="查询列表")
    @PostMapping("/transportationList")
    @ResponseBody
    public TableDataInfo transportationList(Transportation transportation){
        List<Transportation> list= transportationService.transportationList(transportation);
        return  getDataTable(list);
    }}

